package cn.play.cardgame.util;

import android.view.View;
import android.view.animation.AlphaAnimation;

public class AnimationUtils {
	private static AnimationUtils mInstance;
	private AlphaAnimation mHideAnimation = null;
	private AlphaAnimation mShowAnimation = null;

	private AnimationUtils() {
	}

	public static AnimationUtils getInstance() {
		if (mInstance == null)
			mInstance = new AnimationUtils();
		return mInstance;
	}

	// 渐渐隐藏动画
	public void setHideAnimation(View view, int duration) {
		if (null == view || duration < 0) {
			return;
		}
		if (null != mHideAnimation) {
			mHideAnimation.cancel();
		}
		mHideAnimation = new AlphaAnimation(1.0f, 0.0f);
		mHideAnimation.setDuration(duration);
		mHideAnimation.setFillAfter(true);
		view.startAnimation(mHideAnimation);
	}

	// 渐渐显示动画
	public void setShowAnimation(View view, int duration) {
		if (null == view || duration < 0) {
			return;
		}
		if (null != mShowAnimation) {
			mShowAnimation.cancel();
		}
		mShowAnimation = new AlphaAnimation(0.0f, 1.0f);
		mShowAnimation.setDuration(duration);
		mShowAnimation.setFillAfter(true);
		view.startAnimation(mShowAnimation);
	}
}
